<?php
/** 
 * Created by RisingSun. 
 * User: MarkSpace 
 * Date: 20210822
 * Time: 11:05 
 * 单页管理
 */
namespace app\content\controller;

use app\admin\model\Login;
use  Mscore\Core\Controller;
use Mscore\Core\Lib\Ossaly;
use Mscore\Core\Lib\Upload;
use Mscore\Core\Log;


class CommonController extends Controller{
   
    /**
     * 初始化自动连接方法
     * @param array $sysmod 
     * @param array $where 
    */
    public function __construct()  
    {    
        $this->login = (new Login())->isAuth();
        if(isset($this->login['code'])&&$this->login['code']==401){
            echo json_encode($this->login);
            Header("Location:".config('server.login_url'));
            exit;
        }
    }   
    
    /**
     * 编辑器上传图片
     * @param array $editor_upload_img 
     * @param array $where 
     */
    public function editor_upload_img(){
        $files=isset($_FILES['file'])?$_FILES['file']:null;//获取文件
        if(!$files){
            $this->echoErrJson('上传文件不能为空');
        }
        if(get('folder')){ $file=get('folder'); }else{ $file='file'; }//获取文件夹类别
        //上传
        $url='static/upload/'.$file.'/'.date('Ym',time());
        if(!is_dir($url)){ @mkdir($url, 0777, true);}
        $filepath = (new Upload)->Uploadfile($_FILES['file'],$url);  //本地
        Log::write(sprintf('"%s" "%s" "%s" "%s" "%s"','上传图片',$filepath,'上传成功', $this->login['info']['aid'], $this->login['info']['username']),'upload/');
        echo json_encode(["code"=>200,"msg"=>"成功上传","data"=>["src"=>"/".$filepath]]);
    }

}